package com.huqing.icu.rentuser.service.impl;

import com.huqing.icu.inout.resp.user.UserInfoQueryResp;
import com.huqing.icu.rentuser.dao.UserDao;
import com.huqing.icu.rentuser.model.User;
import com.huqing.icu.rentuser.service.IUserService;
import com.huqing.icu.utils.CopyUtils;
import com.huqing.icu.utils.ParamValidateUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Stack;

/**
 * 用户信息接口
 *
 * @author huqing
 * @date 2024-11-6 22:15
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserDao userDao;


    @Override
    public User createUser() {
        return null;
    }

    @Override
    public User login() {
        return null;
    }

    @Override
    public Integer destroy(Long userId) {
        return null;
    }

    /**
     * 查询用户信息
     *
     * @param userId
     * @return
     */
    @Override
    public UserInfoQueryResp getByUserId(Long userId) {
        ParamValidateUtils.validateNotNull(userId, "用户ID不能为空");
        User user = userDao.getByUserId(userId);
        if (user == null) {
            ParamValidateUtils.throwInternalErrorExp("用户不存在");
        }

        UserInfoQueryResp userInfoQueryResp = CopyUtils.copy(user, UserInfoQueryResp.class);
        return userInfoQueryResp;
    }

    @Override
    public List<UserInfoQueryResp> getByUserIdList(List<Long> userIdList) {
        ParamValidateUtils.validateNotNull(userIdList, "用户ID不能为空");
        List<User> userList = userDao.selectByUserIdList(userIdList);
        if (userList == null || CollectionUtils.isEmpty(userList)) {
            ParamValidateUtils.throwInternalErrorExp("用户不存在");
        }

        List<UserInfoQueryResp> respList = CopyUtils.copyOriginListToDestList(userList, UserInfoQueryResp.class);
        return respList;
    }


    public int maxDepth(String s) {
        Stack<Character> stack = new Stack<>();

        int max = 0;

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(') {
                stack.push(c);
                max = stack.size() > max ? stack.size() : max;
            } else if (c == ')') {
                stack.pop();
            }
        }
        return max;
    }

}
